#!/bin/bash

do_gnuplot()
{
	app=$1
	page=$2
	title=reply_time_${app}_${page}
	data=results/reply_time_${app}_${page}.csv
	output_file=plots/${title}.png
	if [ -e $data ] ; then
		echo "plotting $data"
		gnuplot <<EOF
# set output
set terminal png
set output "$output_file"
# graph title
set title "$title"
# nicer aspect ratio for image size
set size 1,0.7
# y-axis grid
set grid y
# x-axis label
set xlabel "load"
# y-axis label
set ylabel "time (ms)"
plot "$data" using 1:2 smooth sbezier with lines title "$title"
EOF
	fi
}

do_gnuplot_qps()
{
	app=$1
	page=$2
	title=qps_${app}_${page}
	data=results/reply_time_${app}_${page}.csv
	output_file=plots/${title}.png
	if [ -e $data ] ; then
		echo "plotting $data"
		gnuplot <<EOF
# set output
set terminal png
set output "$output_file"
# graph title
set title "$title"
# nicer aspect ratio for image size
set size 1,0.7
# y-axis grid
set grid y
# x-axis label
set xlabel "load"
# y-axis label
set ylabel "qps"
plot "$data" using 1:(1000/\$2) smooth sbezier with lines title "$title"
EOF
	fi
}

for app in apache django
do
	for page in static app app_data
	do
		# individual plot
		do_gnuplot $app $page
		do_gnuplot_qps $app $page
	done
done

